#include "walktest.h"
#include "command.h"
#include "gesturewalktest.h"

extern WalkTest *Sys;
GestureWalkTest *gestureSys;

// moved this out of main() to make it easier for app developer
// to override
static void CreateSystem(void)
{
  // Create the system driver object
  gestureSys = new GestureWalkTest();
  Sys = gestureSys;
}

int main (int argc, char* argv[])
{
#if defined(CS_PLATFORM_WIN32) && defined(CS_COMPILER_MSVC)
  cswinMinidumpWriter::EnableCrashMinidumps ();
#endif
  // Initialize the random number generator
  srand (time (0));

  CreateSystem();

  // Initialize the main system. This will load all needed plugins
  // (3D, 2D, network, sound, ..., engine) and initialize them.
  if (!Sys->Initialize (argc, argv, "/config/walktest.cfg"))
  {
	gestureSys->Report (CS_REPORTER_SEVERITY_ERROR,
	  "Error initializing system!");
	Cleanup();
	return -1;
  }

  // Start the 'autoexec.cfg' script and fully execute it.
  csCommandProcessor::start_script ("/config/autoexec.cfg");
  char cmd_buf[512];
  while (csCommandProcessor::get_script_line (cmd_buf, 511))
	csCommandProcessor::perform_line (cmd_buf);

  // If there is another script given on the commandline
  // start it but do not execute it yet. This will be done
  // frame by frame.
  if (gestureSys->auto_script)
	csCommandProcessor::start_script (gestureSys->auto_script);

  // The main loop.
  csDefaultRunLoop(gestureSys->object_reg);

  Cleanup ();

  return 0;
}

